package com.bwie.controller;

import com.bwie.pojo.TbMenu;
import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.utils.Result;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.UserLoginVo;
import com.bwie.vo.UserPageInfo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/user/index")
@Slf4j
public class IndexController {

    @Autowired
    TbUserService userService;

    @PostMapping("/loginIndex")
    public R index(){

        log.info("启动了");
        return R.OK();
    }

    @ApiOperation("用户登录")
    @PostMapping("/userLogin")
    public Result userLogin(@RequestBody @Validated UserLoginVo userLoginVo){


        return userService.userLogin(userLoginVo);
    }

    @ApiOperation("发送kafka")
    @PostMapping("/sendMess/{message}")
    public R sendMess(@PathVariable("message")String message){

        return userService.send(message);
    }


    @ApiOperation("获取权限菜单")
    @PostMapping("/getMenuList")
    public R getMenuList(HttpServletRequest request){

        return userService.getMenuList(request);
    }

    @ApiOperation("上传图片")
    @PostMapping("/uploadImage")
    public R uploadImage(@RequestPart(name = "file") MultipartFile file)  {

        return userService.uploadImage(file);
    }

    @ApiOperation("用户列表分页查询")
    @PostMapping("/userListPage")
    public R userListPage(@RequestBody UserPageInfo userPageInfo){

        return userService.userListPage(userPageInfo);
    }


    @ApiOperation("修改用户对象")
    @PostMapping("/updateUserById")
    public R updateUserById(@RequestBody TbUser tbuser){
        return userService.updateUserById(tbuser);
    }

    @ApiOperation("删除用户")
    @PostMapping("/deleteById/{userId}")
    public R deleteById(@PathVariable(name = "userId") Integer userId){
        return  userService.deleteById(userId);
    }

    @ApiOperation("用户批量删除")
    @PostMapping("/DeleteAll")
    public R DeleteAll(@RequestBody List<TbUser> userlist){

        return userService.DeleteAll(userlist);
    }

    @ApiOperation("用户审核")
    @PostMapping("/checkStatus")
    public R checkStatus(@RequestBody TbUser tbUser){
        return userService.checkStatus(tbUser);
    }

    @ApiOperation("创建索引")
    @PostMapping("/createIndex")
    public R createIndex(){
        return userService.createIndex();
    }

    @ApiOperation("同步mysql数据")
    @PostMapping("/synMysql")
    public R synMysql(){
        return userService.synMysql();
    }

    @ApiOperation("es商户列表")
    @PostMapping("esUserList")
    public R esUserList(@RequestBody PageInfoVo pageInfoVo){
        return userService.esUserList(pageInfoVo);
    }
}
